package com.gujiangbo.es;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;

/**
 * @Author: gujiangbo.co
 * @Contact: 646832012@qq.com
 * @Date: 2022/4/28 10:16
 * @Version: 1.0
 * @Description:
 */
public class ElasticSearchClient {

    private static volatile RestHighLevelClient instance = null;

    public static RestHighLevelClient getInstance() {
        if (instance == null) {
            synchronized (ElasticSearchClient.class) {
                if (instance == null) {
                    instance = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
                }
            }
        }
        return instance;
    }

    public static void close() {
        if (instance != null) {
            try {
                instance.close();
            } catch (Exception e) {
            }
        }
    }
}
